// Copyright (c) 2010 Manuel Peinado Gallego <manuel.peinado@gmail.com>
// Distributed under the MIT license


#include "stdafx.h"
#include "Plane.h"
#include "Common.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


bool rayPlaneIntersection(const gx::Vec3 & rayO, const gx::Vec3 & rayDir,  
    const Plane & plane, gx::Vec3 & result)
{
    double dot = rayDir.dot(plane.n);
    if(fabs(dot) < EPSILON)
    {
        return false;
    }

    double t = -(rayO.dot(plane.n) + plane.D) / dot;
    if(t < 0.)
    {
        return false;
    }

    result = rayO + t * rayDir;
    return true;
}

